package com.job.netease;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author angzhijin
 * @Description
 * @create 2022-08-27 7:07 下午
 */
public class Netease0827 {
    public static void main(String[] args) {
//        A(args);
        B(args);
    }


    /**
     * 3
     * 3 5
     * 1x1
     * xox
     * 1x1
     *
     * 3 7
     * 1x1
     * xox
     * 1x1
     *
     * 5 7
     * 13S31
     * LKcKL
     * Sc2cS
     * LKcKL
     * 13S31
     */
    public static void A(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int t = 0; t < T; t++) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            sc.nextLine();
            char[][] paper = new char[n][n];
            for (int i = 0; i < n; i++) {
                paper[i] = sc.nextLine().toCharArray();
            }
            if(t!=T-1) sc.nextLine();
            char[][] wall = new char[m][m];
            int midP = n/2,  midW = m/2;
            for (int i = 0; i+midW < m; i++) {
                for (int j = 0; j+midW < m; j++) {
                    char ch = paper[(midP+i)%n][(midP+j)%n];
                    wall[midW+i][midW+j] = ch;
                    wall[midW+i][midW-j] = ch;
                    wall[midW-i][midW+j] = ch;
                    wall[midW-i][midW-j] = ch;
                }
            }
            for (char[] line : wall) {
                System.out.println(String.copyValueOf(line));
            }
            System.out.println();
        }
    }

    public static void B(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for (int t = 0; t < T; t++) {
            int N = sc.nextInt();
            int[][] matrixs = new int[N][4];
            int[] visited = new int[N];
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < 4; j++) {
                    matrixs[i][j] = sc.nextInt();
                }
            }
            int sum= 0;
            for (int i = 0; i < N-1; i++) {
                for (int j = i+1; j < N; j++) {
                    sum+= point(matrixs, i, j, visited);
                }
            }
            System.out.println(sum);
        }
    }

    public static int point(int[][] matrixs, int a, int b, int[] visited){
        int[] matrix1 = matrixs[a];
        int[] matrix2 = matrixs[b];
        int[] xs = new int[]{matrix1[0],matrix1[2],matrix2[0],matrix2[2]};
        int[] ys = new int[]{matrix1[1],matrix1[3],matrix2[1],matrix2[3]};
        Arrays.sort(xs);
        Arrays.sort(ys);

        int midx = (xs[1]+xs[2])/2;
        int midy = (ys[1]+ys[2])/2;
        // 顶点相交
        if((xs[1]==xs[2]) || (ys[1]==ys[2])) return 0;
        // 不相交
        if(midx<matrix1[0] || midx>matrix1[2] || midy < matrix1[1] || midy>matrix1[3]
            || midx<matrix2[0] || midx>matrix2[2] || midy < matrix2[1] || midy>matrix2[3])
            return 0;
        // 包含（不相交）
        if((matrix1[0]<matrix2[0] && matrix1[2] > matrix2[2] && matrix1[1]<matrix2[1] && matrix1[3] > matrix2[3])
            || (matrix1[0]>matrix2[0] && matrix1[2] < matrix2[2] && matrix1[1]>matrix2[1] && matrix1[3] < matrix2[3]))
            return 0;
        int area1 = (matrix1[2]-matrix1[0])*(matrix1[3]-matrix1[1]);
        int area2 = (matrix2[2]-matrix2[0])*(matrix2[3]-matrix2[1]);
        int area3 = (xs[2]-xs[1])*(ys[2]-ys[1]);
        int area =0;
        if (visited[a]==0) area+=area1;
        if (visited[b]==0) area+=area2;
        visited[a]=1;
        visited[b]=1;
        return area-area3;
    }

}
